<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改店铺信息</title>
    <script src="../plugins/JQuery/jquery-2.1.1.min.js"></script>
    <script src="../plugins/Bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="../plugins/Bootstrap/css/bootstrap.css">
    <!--线上css-->
   <!-- <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">-->
    <script>
        $(function () {

            $.ajax({
                url:'/taobei_web/Store/selectStoreByStoreSessionId',
                dataType:'json',
                success:function (respBean) {
                    if (respBean.status==500){
                        alert(respBean.msg)
                    } else {
                        $("#storeImgOld").attr("src",respBean.data.imgUrl);
                        $("#storeName").val(respBean.data.name);
                     /*   $("#flag").text(respBean.data.flag=='0'?"审核中":"正常营业中");*/
                        $("#storeInfo").val(respBean.data.info);
                        $("#detailAddress").val(respBean.data.address)
                    }
                }
            })
            //提交事件发送ajax请求
            $("#updateStore").click(function () {
                let name = $("#storeName").val();
                let info = $("#storeInfo").val();
                let address = $("#detailAddress").val();
                let file = $('#storeImg')[0].files[0];
                //创建 FormData 对象存储表单信息
                let formData = new FormData();
                formData.append("name",name);
                formData.append("info",info);
                formData.append("address",address);
                formData.append("file",file);
                $.ajax({
                    type:'post',
                    url:'/taobei_web/Store/updateStore',
                    data:formData,
                    contentType:false,
                    processData:false,
                    dataType:'json',
                    success:function (respBean) {
                        if (respBean.status==500){
                            alert(respBean.msg)
                        } else {
                            alert(respBean.msg)
                            location.href="showStore.html"
                        }
                    }
                })
            })

            $('#storeImg').on("change", function () {
                var formData = new FormData();
                let file = $('#storeImg')[0].files[0];
                formData.append("file",file);
                $.ajax({
                    "url": "/taobei_web/Store/upload", // 上传地址
                    "data": formData,
                    "dataType": "json",
                    "type": "post",
                    "contentType": false, //上传文件一定要是false
                    "processData": false,
                    "success": function (obj) {
                        debugger;
                        if (obj.status == 200) {
                            $("#storeImgOld").attr("src",obj.data);
                        }
                    }
                });
            })
        })

    </script>
</head>
<body>

<!--    <img id="storeImgOld" width="200px" height="200px"><br>
    店名<input type="text" placeholder="输入店名" id="storeName"><br>
    状态：<span id="flag"></span><br>
    修改图片：
    <input type="file" id="storeImg"><br>
    店铺简介<input type="text" id="storeInfo" placeholder="店铺简介"><br>
    店铺地址:
    <input type="text" placeholder="详细地址" id="detailAddress">
    <input type="button" value="修改" id="updateStore">-->



    <div class="container">
        <div class="row">
            <div class="span12">
                <form class="form-horizontal">
                    <div class="control-group">
                        <label class="control-label">当前头像</label>
                        <div class="controls">
                            <img id="storeImgOld" width="200px" height="200px"><br>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">修改照片</label>
                        <div class="controls">
                            <input type="file" name="files" id="storeImg" multiple="multiple" accept="image/png,image/jpg,image/gif,image/JPEG">
                            <!--<input type="file" id="storeImg"><br>-->
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">店名</label>
                        <div class="controls">
                            <input type="text" placeholder="输入店名" id="storeName" class="form-control" style="width: 200px"><br>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">店铺地址</label>
                        <div class="controls">
                            <textarea class="form-control" rows="3" placeholder="详细地址" id="detailAddress"></textarea>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">店铺简介</label>
                        <div class="controls">
                            <textarea class="form-control" rows="3" placeholder="店铺简介" id="storeInfo"></textarea>
                            <!--<input type="text" id="storeInfo" placeholder="店铺简介" class="form-control"><br>-->
                        </div>
                    </div>

                    <div class="control-group">
                        <div class="controls">
                            <label class="checkbox"></label>
                            <input type="button" value="修改" id="updateStore" class="btn btn-default">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>